<template>
	<view>
		<view class="order-item">
			<view class="goods-info">
				<image :src="order_info.cover" mode=""></image>
				<view class="info">
					<text class="name">{{order_info.goods_name}}</text>
					<text class="price">￥{{ order_info.goods_amount }}</text>
					<text class="time">下单时间：{{ $db.timeStampToTime(order_info.ctime * 1000) }}</text>
				</view>
			</view>
		</view>
		<view class="card-list">
			<view class="card-item">
				<view class="left"><text>性别</text></view>
				<view class="right">
					<text>{{ order_info.sex == 1 ? '男' : '女' }}</text>
				</view>
			</view>
			<view class="card-item">
				<view class="left"><text>身高</text></view>
				<view class="right">
					<text>{{ order_info.height }}</text>
				</view>
			</view>
			<view class="card-item">
				<view class="left"><text>体重</text></view>
				<view class="right">
					<text>{{ order_info.width }}</text>
				</view>
			</view>
			<view class="card-item">
				<view class="left"><text>是否健身</text></view>
				<view class="right">
					<text>{{ order_info.is_keep == 1 ? '是' : '否' }}</text>
				</view>
			</view>
			<view class="card-item">
				<view class="left"><text>需求</text></view>
				<view class="right">
					<text>{{ order_info.cyclically_name }}</text>
				</view>
			</view>
			<view class="card-item">
				<view class="left"><text>计划开始时间</text></view>
				<view class="right">
					<text>{{ $db.timeStampToYearDay(order_info.p_time * 1000) }}</text>
				</view>
			</view>
			<view class="card-item">
				<view class="left"><text>午餐预约时间</text></view>
				<view class="right">
					<text>{{ $db.timeStampToHourTime(order_info.wu_time * 1000) }}</text>
				</view>
			</view>
			<view class="card-item">
				<view class="left"><text>晚餐预约时间</text></view>
				<view class="right">
					<text>{{ $db.timeStampToHourTime(order_info.wan_time * 1000) }}</text>
				</view>
			</view>
		</view>
		<view class="addr-wrapper">
			<view class="name-and-mobile">
				<text class="name">收货人：{{ addr_item.name }}</text>
				<text class="mobile">{{ addr_item.mobile }}</text>
			</view>
			<text class="addr-info">配送地址：{{ $db.getAddrById(addr_item.area_id) }} {{ addr_item.address }}</text>
			<!-- <text class="tip">注：最晚送餐前两小时可申请推迟、顺延时间或修改地址</text> -->
			<!-- <text class="addr-btn">更换地址</text> -->
		</view>

		<view class="delay-btn">
			<text @click="$db._NavTo('submited-order-page', { order_id })">查看菜品详情</text>
			<text @click="wxPay()" v-if="order_info.pay_status === 1">去支付</text>
			<text v-if="order_info.pay_status === 3" @click="$db._NavTo('comment', { order_id, type: 'plan' })">去评价</text>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				order_id: 0,
				address_id: 0,
				addr_item: {},
				order_info: {}
			};
		},
		onLoad(o) {
			if (o.order_id) {
				this.order_id = o.order_id;
			}
		},
		onShow() {
			this.getData();
		},
		methods: {
			getData: function() {
				this.$api
					.getCycliceOrderDetail({
						order_id: this.order_id
					})
					.then(res => {
						console.log(res);
						this.order_info = res.data;
						this.address_id = res.data.address_id;
						this.addr_item.address = res.data.ship_address
						this.addr_item.area_id = res.data.ship_area_id
						this.addr_item.mobile = res.data.ship_mobile
						this.addr_item.name = res.data.ship_name
						// this.getAddrItem();
					});
			},
			// getAddrItem: function() {
			// 	this.$api
			// 		.getAddressInfo({
			// 			id: this.address_id
			// 		})
			// 		.then(res => {
			// 			// console.log(res);
			// 			this.addr_item = res.data;
			// 		});
			// },
			wxPay: function() {
				// 支付
				this.$api
					.wxPay({
						ids: this.order_id
					})
					.then(ret => {
						if ('data' in ret && ret.data === 10059) {
							this.$db._NavTo('submited-order-page', {
								order_id: res.data.order_id
							}, this.$db.navToMethod[1]);
						} else {
							location.href = ret.data.url
						}
					});
			}
		}
	};
</script>

<style lang="scss">
	page {
		background: #ffffff;
	}

	.card-list {
		margin: 20rpx 0;
		padding: 0 30rpx;
		background: #fff;

		picker+picker {
			.card-item {
				border-top: 1rpx solid #ececec;
			}
		}

		picker+.card-item {
			border-top: 1rpx solid #ececec;
		}
	}

	.card-item {
		padding: 24rpx 0;
		display: flex;
		background: #fff;

		&+.card-item {
			border-top: 1rpx solid #ececec;
		}

		&+picker {
			.card-item {
				border-top: 1rpx solid #ececec;
			}
		}

		text {
			font-size: 24rpx;
			line-height: 28rpx;
			color: rgba(39, 39, 39, 1);
		}

		.left {
			display: flex;
			align-items: center;

			image {
				margin-right: 10rpx;
				width: 42rpx;
				height: 42rpx;
			}

			input {
				margin-left: 50rpx;
				width: 282rpx;
				font-size: 22rpx;
				color: rgba(153, 153, 153, 1);
			}
		}

		.right {
			margin-left: auto;
			display: flex;
			align-items: center;

			text {
				margin-left: 20rpx;
				color: #999999;
			}

			image {
				margin-left: 20rpx;
				width: 12rpx;
				height: 22rpx;
			}
		}
	}

	.order-item {
		padding: 48rpx 12rpx;
		margin: 0 28rpx;
		border-bottom: 2px solid rgba(242, 242, 242, 1);

		.goods-info {
			display: flex;

			image {
				flex: 0 0 138rpx;
				width: 138rpx;
				height: 138rpx;
				border-radius: 10rpx;
			}

			.info {
				flex: 0 0 470rpx;
				padding-left: 22rpx;
				display: flex;
				flex-flow: column;

				.name {
					font-size: 32rpx;
					color: rgba(37, 37, 37, 1);
				}

				.price {
					margin-top: 20rpx;
					color: rgba(37, 37, 37, 1);
				}

				.time {
					margin-top: auto;
					margin-bottom: 8rpx;
					font-size: 22rpx;
					color: #c19101;
				}
			}
		}
	}

	.addr-wrapper {
		box-sizing: border-box;
		margin: 36rpx auto 0;
		padding: 40rpx 58rpx;
		width: 642rpx;
		display: flex;
		flex-flow: column;
		background: #ffffff;
		border-radius: 10rpx;
		border: 1px solid rgba(201, 201, 201, 1);

		.name-and-mobile {
			display: flex;
			align-items: center;

			.name {
				font-size: 26rpx;
				color: #424242;
			}

			.mobile {
				margin-left: auto;
				font-size: 26rpx;
				color: #424242;
			}
		}

		.addr-info {
			margin: 20rpx 0 16rpx;
			font-size: 26rpx;
			color: #424242;
		}

		.tip {
			font-size: 24rpx;
			color: #c19101;
		}

		.addr-btn {
			margin-top: 16rpx;
			margin-left: auto;
			padding: 8rpx 16rpx;
			border: 1px solid rgba(157, 157, 157, 1);
			border-radius: 10rpx;
			color: #c19101;
		}
	}

	.delay-btn {
		margin: 100rpx auto;
		width: 554rpx;
		height: 72rpx;
		text-align: center;
		display: flex;
		// border-radius: 36rpx;
		// background: #DFBB50;

		text {
			flex: 1 1 100%;
			display: block;
			height: 100%;
			line-height: 72rpx;
			color: #ffffff;
			font-size: 30rpx;
			font-weight: 500;
			background: #dfbb50;
			border-radius: 36rpx;

			&+text {
				margin-left: 20rpx;
			}
		}
	}
</style>
